package com.whmall.service.crm.common;

import org.mindrot.jbcrypt.BCrypt;
import org.springframework.stereotype.Component;

/**
 * BCrypt算法的密码编码器
 *
 * @author alex
 * @since 2020/7/22
 */
@Component
public class BCryptPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(String decodedPassword) {
        return BCrypt.hashpw(decodedPassword, BCrypt.gensalt());
    }

    @Override
    public boolean validate(String encodedPassword, String decodedPassword) {
        return BCrypt.checkpw(decodedPassword, encodedPassword);
    }
}
